package com.aaa.ssm.controller;

import com.aaa.ssm.entity.StudentDTO;
import com.aaa.ssm.entity.StudentVO;
import com.aaa.ssm.query.StudentQuery;
import com.aaa.ssm.result.AjaxResult;
import com.aaa.ssm.service.StudentService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.FileCopyUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("stu")
@Api(tags = "学生管理模块")
public class StudentController {


    @Autowired
    private StudentService studentService;

    @RequestMapping("query")
    public AjaxResult queryStudent(StudentQuery Query) {
        Map<String, Object> map = studentService.queryStudent(Query);
        return AjaxResult.success(map);
    }

    @RequestMapping("delete/{id}")
    public AjaxResult deleteStudent(@PathVariable("id") Integer id) {
        Integer i = studentService.deleteStudent(id);
        if (i > 0) {
            return AjaxResult.success(i);
        }
        return AjaxResult.error();
    }

    @RequestMapping("add")
    public AjaxResult addStudent(@Validated StudentDTO studentDTO) {
        Integer i = studentService.addstudent(studentDTO);
        if (i > 0) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    @RequestMapping("get/{id}")
    public AjaxResult getStudentById(@PathVariable("id") Integer id) {

            StudentDTO studentById = studentService.getStudentById(id);
            return AjaxResult.success(studentById);

    }

    @RequestMapping ("update")
    public AjaxResult update(StudentVO studentDTO) {
        System.out.println(studentDTO);

        Integer i = studentService.updateStudent(studentDTO);
        if (i > 0) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error();


        }
    }
}
